﻿#pragma once

#include "common.h"
#include "context.h"
#include "keyed.h"
#include "serializable.h"
#include "rendercxt.h"
#include <vector>

namespace anip
{
	class GraphicsRenderer;

	class GraphicObject
	{
	private:
		int _version = 0;

	public:
		void markEdit() { _version++; }
		int version() const { return _version; }
		virtual int length() const = 0;
		virtual GraphicsRenderer* createRenderer() = 0;
	};

	class GraphicsRenderer
	{
	protected:
		int _version = 0;
		double _presentationStartTime = 0;
		float _currentFrame = 0;
		bool _active = false;

	public:
		int version() const { return _version; }
		float currentFrame() const { return _currentFrame; }
		virtual GraphicObject& graphicObject() const = 0;

		virtual ~GraphicsRenderer() = default;

		virtual void update() 
		{
			_version = graphicObject().version();
		}

		virtual void setFrame(float t)
		{
			assert(_active);
			_currentFrame = t;
		}

		bool isActive() const { return _active; }

		virtual void activate()
		{
			assert(!_active);
			_active = true;
			_presentationStartTime = anip::time();
		}

		virtual void deactivate()
		{
			assert(_active);
			_active = false;
		}

		virtual void setPresentationFrame(double realTime)
		{
			assert(_active);
		}

		virtual void render(GraphicsRenderContext& cxt) = 0;
	};

	class FrameGroup : public GraphicObject, public Serializable<FrameGroup>
	{
		friend class Sequence;

		serializable_abstract;

	public:
		FrameGroup() {}
		FrameGroup(const FrameGroup& obj) = delete;
	};

}